﻿using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CooNETClient")]
[assembly: AssemblyDescription(".NET klient pre Fabasoft Components")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CooNETClient")]
[assembly: AssemblyCopyright("Copyright ©  2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6482b9e2-3509-4bf8-8318-e68b87dc795c")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

internal static class AssemblyInfo
{
    private static string _title;
    private static string _description;
    private static string _configuration;
    private static string _company;
    private static string _product;
    private static string _copyright;
    private static string _trademark;
    private static string _culture;

    private static string _assemblyVersion;
    private static string _fileVersion;

    private static readonly Assembly _assembly = typeof (FscNET.Client.Main).Assembly;

    private static string GetAttributeValue<T>()
    {
        try
        {
            if (typeof(T) == typeof(AssemblyVersionAttribute))
                return _assembly.GetName().Version.ToString();
            System.Attribute a = System.Attribute.GetCustomAttribute(_assembly, typeof (T));
            if (a is AssemblyTitleAttribute) return ((AssemblyTitleAttribute) a).Title;
            if (a is AssemblyDescriptionAttribute) return ((AssemblyDescriptionAttribute) a).Description;
            if (a is AssemblyConfigurationAttribute) return ((AssemblyConfigurationAttribute)a).Configuration;
            if (a is AssemblyCompanyAttribute) return ((AssemblyCompanyAttribute)a).Company;
            if (a is AssemblyProductAttribute) return ((AssemblyProductAttribute)a).Product;
            if (a is AssemblyCopyrightAttribute) return ((AssemblyCopyrightAttribute)a).Copyright;
            if (a is AssemblyTrademarkAttribute) return ((AssemblyTrademarkAttribute)a).Trademark;
            if (a is AssemblyCultureAttribute) return ((AssemblyCultureAttribute)a).Culture;
            if (a is AssemblyFileVersionAttribute) return ((AssemblyFileVersionAttribute)a).Version;
            return "";
        }
        catch
        {
            return "";
        }
    }

    public static string Title
    {
        get { return _title ?? (_title = GetAttributeValue<AssemblyTitleAttribute>()); }
    }
    public static string Description
    {
        get { return _description ?? (_description = GetAttributeValue<AssemblyDescriptionAttribute>()); }
    }
    public static string Configuration
    {
        get { return _configuration ?? (_configuration = GetAttributeValue<AssemblyConfigurationAttribute>()); }
    }
    public static string Company
    {
        get { return _company ?? (_company = GetAttributeValue<AssemblyCompanyAttribute>()); }
    }
    public static string Product
    {
        get { return _product ?? (_product = GetAttributeValue<AssemblyProductAttribute>()); }
    }
    public static string Copyright
    {
        get { return _copyright ?? (_copyright = GetAttributeValue<AssemblyCopyrightAttribute>()); }
    }
    public static string Trademark
    {
        get { return _trademark ?? (_trademark = GetAttributeValue<AssemblyTrademarkAttribute>()); }
    }
    public static string Culture
    {
        get { return _culture ?? (_culture = GetAttributeValue<AssemblyCultureAttribute>()); }
    }
    public static string Version
    {
        get { return _assemblyVersion ?? (_assemblyVersion = GetAttributeValue<AssemblyVersionAttribute>()); }
    }
    public static string FileVersion
    {
        get { return _fileVersion ?? (_fileVersion = GetAttributeValue<AssemblyFileVersionAttribute>()); }
    }
}
